<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Goldcoins extends Model
{
    protected $table = "goldcoins";

    public function getDetail($data)
    {
        $lit = self::where(['id'=>$data['id']])->first();
        if(empty($lit)){
            return "该龙币不存在！";
        }
        //发行期
        $gold_info =  (new Giveout())->where(['id'=>$lit->out_id])->first();
        $lit->out_time = $gold_info->created_at->toDateString();
        $lit->numbers = $gold_info->numbers;
        $lit->numbers = $gold_info->numbers;
        $lit->title = $gold_info->title;
        $lit->types = $gold_info->types;
        $lit->user_info = null;
        $lit->buy_time = null;
        if($lit->sale_state == 1){
            $gold = (new GiveoutGoldCoinsLog())->where(['gold_id'=>$data['id'],'states'=>1])->first();
            if($gold){
                $order = (new Order())->where(['id'=>$gold->order_id])->first();
                $user = (new MemberUser())->select("phone","username","nickname")->where(['id'=>$order->user_id])->first()->toArray();
                $lit->user_info =  $user;
                $lit->buy_time =  $order->pay_time;
            }
        }
        return $lit->toArray();
    }
}
